home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8888 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.interpath.net!mercury!softbase
  2. From: softbase@mercury.interpath.net (Scott McMahan - Softbase Systems)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tradition or what?
  5. Date: 7 Mar 1996 13:38:12 GMT
  6. Organization: Interpath -- Providing Internet access to North Carolina
  7. Message-ID: <4hmos4$ij2@news.interpath.net>
  8. References: <4g0elg$mdr@redstone.interpath.net> <4h0bbo$c0q@fohnix.metronet.com> <4h7ce0$ojd@news.interpath.net> <4h85sm$lm0@texas.nwlink.com> <danpop.825961872@rscernix> <313C5CD1.1209@oc.com>
  9. NNTP-Posting-Host: mercury.interpath.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Larry Weiss (lfw@oc.com) wrote:
  13.   
  14. : > Actually, the second rule is quite good (except that '2' should be replaced
  15. : > by '1' :-)  Magic constants embedded in the code are a huge nuisance
  16. : > for maintenability.  [...]
  17.  
  18. : I agree that there are good uses for giving a literal a name, and using
  19. : that name instead of repeated usage of the literal, but to make a
  20. : mandate that even if the literal were referenced only once you must give
  21. : it a name would seem too extreme.
  22.  
  23. From personal experience, I think you can't be too extreme. I've been
  24. burned by literals before. I've come to the conclusion that magic
  25. numbers in the code are evil and should be done away with. Anything
  26. that isn't a universal, unchanging constant (like an integer being 32
  27. bits :)), something like a law of physics, needs to be a constant in
  28. the program. I always #define it, too, since C has broken const
  29. constants that can't be used as initializers (which defeats the whole
  30. point of const).
  31.  
  32. I still have code that has to go through an SQL preprocessor before the
  33. C preprocessor which has literals in array definitions. Ugh. Some SQL
  34. preprocessors can handle #defines, some can't, so I have to pander to
  35. the lowest common denominator.
  36.  
  37. Scott
  38.  
  39.